package com.example.chatchatbackend.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.Shopping;
import com.example.chatchatbackend.entity.dto.UserTags;
import com.example.chatchatbackend.entity.vo.response.ShoppingVO;
import com.example.chatchatbackend.entity.vo.response.ShoppingVO;
import com.example.chatchatbackend.service.ShoppingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */
@Slf4j
@RestController
@RequestMapping("/api/shopping")
public class ShoppingController {

    @Autowired
    private ShoppingService shoppingService;

    @GetMapping
    public RestBean<List<Shopping>> getAll(){
        List<Shopping> shoppingList = shoppingService.getAll();
        log.info("getAll-shopping:{}",shoppingList);
        return RestBean.success(shoppingList);
    }

    @PostMapping
    public RestBean<ShoppingVO> insertShopping(@RequestBody ShoppingVO shoppingVO){
        ShoppingVO insertShoppingVO = shoppingService.insertShopping(shoppingVO);
        return RestBean.success(insertShoppingVO);

    }

    @PostMapping("/list")
    public RestBean<List<ShoppingVO>> insertShoppingList (@RequestBody List<ShoppingVO> shoppingVO){
        List<ShoppingVO> ShoppingList = shoppingService.insertShoppingList(shoppingVO);
        return RestBean.success(ShoppingList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<Shopping>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(shoppingService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<ShoppingVO> updateShopping(@RequestBody ShoppingVO shoppingVO){
        return RestBean.success(shoppingService.updateShopping(shoppingVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        shoppingService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }

    @GetMapping("/ids")
    public RestBean<List<ShoppingVO>> findByIds(@RequestBody List<Integer> ids){
        List<ShoppingVO> shoppingVOList = shoppingService.findByIds(ids);
        return RestBean.success(shoppingVOList);
    }

}
